#include "ChatrServer.hpp"
#include <iostream>
#include <unistd.h>
#include <string>
#include "Routine.hpp"
#include "ThreadPool.hpp"

using task_t = std::function<void()>;

void Resver(const std::string &str)
{
    std::cout << "请输入：" << str << " ip地址 " << std::endl;
}

int main(int argc, char *argv[])
{
    if (argc != 2)
    {
        Resver(argv[0]);
        exit(0);
    }
    EnableConsolseSyncStrategy();
    uint16_t port = std::stoi(argv[1]);
    std::unique_ptr<Route> r = std::make_unique<Route>();
    auto tp = ThreadPool<task_t>::GetInstance();
    std::unique_ptr<Server> usvr = std::make_unique<Server>(port,
                                                            [&r, &tp](int sockfd, std::string message, InetAddr addr)
                                                            {
                                                                task_t task = std::bind(&Route::RouteMessageToAll, r.get(), sockfd, message, addr);
                                                                tp->Enqueue(task);
                                                            });
    usvr->Init();
    usvr->Start();

    return 0;
}